package joe.json;

import java.util.ArrayList;
import java.util.List;

import joe.model.MusicInfo;

import org.json.JSONArray;
import org.json.JSONObject;

public class JsonParser {
	public static List<MusicInfo> parser(String jsonStr) {
		List<MusicInfo> musicInfos = new ArrayList<MusicInfo>();
		try {
			JSONArray jsonArray = new JSONArray(jsonStr);
			MusicInfo info = null;
			JSONObject json = null;
			for (int i = 0; i < jsonArray.length(); i++) {
				info = new MusicInfo();
				json = jsonArray.getJSONObject(i);
				int serverId = json.getInt("id");
				String title = json.getString("title");
				String lrc = json.getString("lrc");
				int size = json.getInt("size");
				info.setServerId(serverId);
				info.setTitle(title);
				info.setLrc(lrc);
				info.setSize(size);
				musicInfos.add(info);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return musicInfos;
	}
}
